//
//  QMySelfHeadCell.m
//  QoilPublic
//
//  Created by 杨凯 on 16/7/4.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QMySelfHeadCell.h"
#import "UIButton+WebCache.h"
@interface QMySelfHeadCell()

@property (weak, nonatomic) IBOutlet UIButton *headButton;

@property (weak, nonatomic) IBOutlet UIButton *loginButton;

@property (weak, nonatomic) IBOutlet UILabel *userLabel;

@property (weak, nonatomic) IBOutlet UIView *bacView;

@property (weak, nonatomic) IBOutlet UILabel *leftLabel;

@property (weak, nonatomic) IBOutlet UILabel *rightLabel;

@property (weak, nonatomic) IBOutlet UIImageView *headFrameImage;

@end
@implementation QMySelfHeadCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _headButton.clipsToBounds = YES;
    _headButton.layer.cornerRadius = 35;
    _loginButton.layer.borderColor = [UIColor whiteColor].CGColor;
    _loginButton.layer.borderWidth = 0.5;
    _loginButton.layer.cornerRadius = 4.0;
    
    _bacView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [_bacView addGestureRecognizer:tap];
}

- (void)tapAction{

    if(self.dtBlock){
        self.dtBlock();
    }
}

- (void)setLoginModel:(QLoginModel *)loginModel{
    _loginModel = loginModel;
    if(_loginModel){
        _userLabel.hidden = NO;
        _loginButton.hidden = YES;
        if(_loginModel.nickName.length > 0){
            _userLabel.text = _loginModel.nickName;
        }else{
            _userLabel.text = [QUserInfo sharedInfo].loginModel.tel;
        }
        if(_loginModel.headImg.length > 0){
            [self.headButton sd_setImageWithURL:[NSURL URLWithString:_loginModel.headImg] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"head_icon"]];
        }else{
            [self.headButton setImage:[UIImage imageNamed:@"head_icon"] forState:UIControlStateNormal];
        }
        _headFrameImage.hidden = NO;
        if ([_loginModel.balance floatValue]>0) {
            _headFrameImage.image = [UIImage imageNamed:@"mySelf_VIPhead"];
        }else{
            _headFrameImage.image = [UIImage imageNamed:@"mySelf_head"];
        }
        
        if([_loginModel.marketingStatus isEqualToString:@"0"]){
            _leftLabel.text = @"我的收益";
            _rightLabel.text = [NSString stringWithFormat:@"￥%@",_loginModel.marketingAmount];
        }else if ([_loginModel.marketingStatus isEqualToString:@"1"]){
            _leftLabel.text = @"申请成为兼职地推";
            _rightLabel.text = [NSString stringWithFormat:@"您已被删除"];
        }else if ([_loginModel.marketingStatus isEqualToString:@"2"]){
            _leftLabel.text = @"申请成为兼职地推";
            _rightLabel.text = [NSString stringWithFormat:@"您已被禁用"];
        }else if ([_loginModel.marketingStatus isEqualToString:@"3"]){
            _leftLabel.text = @"申请成为兼职地推";
            _rightLabel.text = [NSString stringWithFormat:@"待审核"];
        }else if ([_loginModel.marketingStatus isEqualToString:@"4"]){
            _leftLabel.text = @"申请成为兼职地推";
            _rightLabel.text = [NSString stringWithFormat:@"审核不通过"];
        }else if ([_loginModel.marketingStatus isEqualToString:@"99"]){
            _leftLabel.text = @"申请成为兼职地推";
            _rightLabel.text = @">";
        }
        
    }else if([QUserInfo sharedInfo].loginModel && !_loginModel){
        _userLabel.hidden = NO;
        _userLabel.text = [QUserInfo sharedInfo].loginModel.nickName;
        _loginButton.hidden = YES;
        [self.headButton setImage:[UIImage imageNamed:@"head_icon"] forState:UIControlStateNormal];
        _leftLabel.text = @"申请成为兼职地推";
        _rightLabel.text = @">";
    }else if (![QUserInfo sharedInfo].loginModel){
        _userLabel.hidden = YES;
        _loginButton.hidden = NO;
        _leftLabel.text = @"申请成为兼职地推";
        _rightLabel.text = @">";
        [self.headButton setImage:[UIImage imageNamed:@"head_icon"] forState:UIControlStateNormal];
        _headFrameImage.hidden = YES;
    }
}

- (IBAction)loginAction:(id)sender {
    if(self.loginBlock){
        self.loginBlock();
    }
}

- (IBAction)headButtonAction:(id)sender {
    if(self.headBlock){
        self.headBlock();
    }
}



@end
